//
//  AddImageButton.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/9/7.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "AddImageButton.h"

@interface AddImageButton()

@property (nonatomic,weak) UIButton *deleteBtn;

@end
@implementation AddImageButton

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self addDeleteBtn];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self =[super initWithCoder:aDecoder]) {
        [self addDeleteBtn];
    }
    return self;
}
- (void)addDeleteBtn
{
    UIButton *deleteBtn = [[UIButton alloc]init];
    [deleteBtn setImage:GetImage(@"delete") forState:UIControlStateNormal];
    [self addSubview:deleteBtn];
    deleteBtn.hidden = YES;
    [deleteBtn addTarget:self action:@selector(deleteClick) forControlEvents:UIControlEventTouchUpInside];
    self.deleteBtn = deleteBtn;
}
- (void)deleteClick
{
    if (self.deleteBlock) {
        self.deleteBlock(self);
    }
}

- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
{
    [super setBackgroundImage:image forState:state];
    //根据image的标识符判断是不是占位图
    if ([image.accessibilityIdentifier isEqualToString:@"btn_upload_image_normal"]) {
        self.deleteBtn.hidden = YES;
    }else{
        self.deleteBtn.hidden = NO;
    }
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.deleteBtn.frame = CGRectMake(self.bounds.size.width-25, -15, 40, 40);
}

@end
